<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>添加分享</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" />
    <link rel="stylesheet" href="/static/ui/css/ui.css" />
</head>

<body>
    <form class="layui-form" action="" lay-filter="editform">
        <div class="mainBox">
            <div class="main-container">
                <div class="main-container">
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block" style="line-height:36px">
                            <div id="title"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">分享给</label>
                        <div class="layui-input-block">
                            <div id="user-area" class="xm-select-demo"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否可编辑</label>
                        <div class="layui-input-block">
                            <input type="radio" name="can_edit" value="1" title="启用">
                            <input type="radio" name="can_edit" value="0" title="禁用" checked="">
                        </div>
                    </div>
                    <!--div class="layui-form-item">
                        <label class="layui-form-label">分享到外部</label>
                        <div class="layui-input-block">
                            <input type="radio" name="can_out" value="1" title="启用">
                            <input type="radio" name="can_out" value="0" title="禁用" checked="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">外部地址</label>
                        <div class="layui-input-block" id="outurl" style="line-height:36px">
                        </div>
                    </div-->

                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="share-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
            </div>
        </div>
    </form>
    <script src="../config.js"></script>
    <script src="/static/layui/layui.js"></script>
    <script src="/static/ui/ui.js"></script>
    <script src="/static/utils/xm-select.js"></script>
    <script src="../utils/select.js"></script>
    <script>
        layui.use(['form', 'layer', 'tree'], function () {
            let form = layui.form
                , layer = layui.layer
                , $ = layui.$
                , req = _req()
                , id = req.id
                , type = req.type
                , ref_id = req.ref_id ? req.ref_id * 1 : 0;
            
            //$('#outurl').html(`http:/gdoa.roter.me/group/share?type=${type}&id=${id}`)
            const renderSelect = (res) => {
                getElSelect(res.userlist, res.to_user_id, 'user-area', 'checkbox', false, {name : 'to_user_id'});
            }
            if (id) {
                //渲染
                _get(layui, 'share/touserBefore?id=' + id + '&type=' + type + '&ref_id=' + ref_id, res => {
                    //console.log(res)
                    form.val('editform', res)
                    renderSelect(res)
                    $('#title').html(res.title)
                });
            } else {
                layer.msg('id error')
            }

            //监听提交
            form.on('submit(share-save)', function (data) {
                data = data.field;
                if(!id){
                    layer.msg('id error!')
                    return false;
                }
                if(!type){
                    layer.msg('type error!')
                    return false;
                }
                data.data_id = id;
                data.type = type;
                data.ref_id = ref_id;
                let postUrl = 'share/touser';
                
                //console.log(data)
                //return false;
                _post(layui, postUrl, data, res => {
                    //console.log(res)
                    //parent.location.reload()
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页

                })

                return false;
            });




        });
    </script>

</body>

</html>